<template>
	<view class="container">
		<view class="head-hosp">{{result.hospName}}</view>
		<view class="line"></view>
		<view class="result-body">
			<view class="result-item">
				<view class="result-item-child">
					<view>就诊人：</view>
					<view class="result-text">{{result.userName}}</view>
				</view>
				<view class="result-item-child">
					<view>年龄：</view>
					<view class="result-text">{{age}}</view>
				</view>
			</view>
			<view class="result-item">
				<view class="result-item-child">
					<view>性别：</view>
					<view class="result-text">{{gender}}</view>
				</view>
				<view class="result-item-child">
					<view>开方科室：</view>
					<view class="result-text">检验科</view>
				</view>
			</view>
			<view class="result-item">
				<view style="margin-left: 10px;">报告时间：</view>
				<view>{{result.updateTime}}</view>
			</view>
			<view class="line"></view>
			<uni-table border stripe emptyText="暂无更多数据">
				<uni-tr>
					<uni-th align="center" width="30px">检测项目</uni-th>
					<uni-th align="center" width="30px">结果</uni-th>
					<uni-th align="center" width="30px">参考值</uni-th>
				</uni-tr>
				<uni-tr>
					<uni-td align="center">{{result.itemName}}</uni-td>
					<uni-td align="center" v-if="result.itemResult==0">阴性</uni-td>
					<uni-td align="center" v-else style="color: #E43D33;">阳性</uni-td>
					<uni-td align="center">阴性</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderId:-1,
				result:{},
				age:23,
				gender:'男'
			};
		},
		onLoad(options) {
			this.orderId = options.orderId
		},
		mounted() {
			this.getResultById()
		},
		methods:{
			getResultById(){
				const order = {
					orderId:this.orderId
				}
				uni.request({
					url:'http://192.168.43.224:9002/orderresult/getOrderResultList/1/1',
					method:'GET',
					data:order,
					success: (res) => {
						this.result = res.data.data.records[0]
						var idcard = this.result.certificateId
						this.idCard(idcard)
					}
				})
			},
			idCard(IdCard){
				if (parseInt(IdCard.substr(16, 1)) % 2 == 1) {
				    this.gender = '男'
				} else {
				    this.gender = '女'
				}
				
				var ageDate = new Date()
				var month = ageDate.getMonth() + 1
				var day = ageDate.getDate()
				var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1
				if (IdCard.substring(10, 12) < month || IdCard.substring(10, 12) == month && IdCard.substring(12, 14) <= day) {
				    age++
				}
				if (age <= 0) {
				    age = 1
				}
				this.age = age
			}
		}
	}
</script>

<style lang="scss">
.container{
	background-color: #FFFFFF;
	.head-hosp{
		text-align: center;
		font-weight: bold;
		margin-top: 15px;
		font-size: 20px;
	}
	.line{
		margin-top: 10px;
		background-color: #6A6A6A;
		height: 2px;
		width: 100%;
	}
	.result-body{
		margin-top: 10px;
		.result-item{
			display: flex;
			padding-bottom: 10px;
			.result-item-child{
				width: 300px;
				display: flex;
				margin-left: 10px;
				margin-right: 40px;
				
			}
		}
	}
	
}
</style>
